package gt.edu.usac.viewcontroller.backing.app;

import gt.edu.usac.model.am.AppModuleImpl;

import gt.edu.usac.model.vo.centroViewImpl;

import gt.edu.usac.model.vo.idiomaNivelSeccionViewImpl;
import gt.edu.usac.model.vo.idiomaNivelViewImpl;
import gt.edu.usac.model.vo.idiomaViewImpl;

import gt.edu.usac.viewcontroller.utils.JSFUtils;

import javax.faces.component.html.HtmlForm;

import javax.faces.component.html.HtmlOutputText;

import javax.faces.context.FacesContext;
import javax.faces.el.ValueBinding;

import oracle.adf.model.BindingContext;
import oracle.adf.model.binding.DCDataControl;
import oracle.adf.view.faces.component.core.data.CoreColumn;
import oracle.adf.view.faces.component.core.data.CoreTable;
import oracle.adf.view.faces.component.core.input.CoreInputText;
import oracle.adf.view.faces.component.core.layout.CorePanelForm;
import oracle.adf.view.faces.component.core.layout.CorePanelGroup;
import oracle.adf.view.faces.component.core.nav.CoreCommandButton;

import oracle.adf.view.faces.component.core.nav.CoreCommandLink;


import oracle.binding.BindingContainer;
import oracle.binding.OperationBinding;

import oracle.jbo.ApplicationModule;
import oracle.jbo.Row;

public class NuevoIdioma {
    private HtmlForm form1;
    private HtmlOutputText outputText1;
    private BindingContainer bindings;
    private CorePanelGroup panelGroup2;
    private CorePanelGroup panelGroup3;
    private CoreTable table1;
    private CoreColumn column1;
    private CoreColumn column2;
    private CoreCommandLink commandLink1;
    private CoreCommandLink commandLink2;
    private CoreCommandButton commandButton3;
    private CoreCommandButton commandButton1;
    private CoreCommandButton commandButton2;
    private CorePanelForm panelForm1;
    private CoreInputText inputText1;
    private CoreCommandButton commandButton4;
    private CoreCommandButton commandButton5;

    public void setForm1(HtmlForm form1) {
        this.form1 = form1;
    }

    public HtmlForm getForm1() {
        return form1;
    }


    public void setOutputText1(HtmlOutputText outputText1) {
        this.outputText1 = outputText1;
    }

    public HtmlOutputText getOutputText1() {
        return outputText1;
    }

    public BindingContainer getBindings() {
        return this.bindings;
    }

    public void setBindings(BindingContainer bindings) {
        this.bindings = bindings;
    }

    public String commandButton1_action() {
        BindingContainer bindings = getBindings();
        OperationBinding operationBinding = 
            bindings.getOperationBinding("Commit");
        Object result = operationBinding.execute();
        if (operationBinding.getErrors().isEmpty()) {            
            operationBinding = bindings.getOperationBinding("Create");
            operationBinding.execute();
            return null;
        }
        return null;
    }


    public String commandButton2_action2() {
        /*AppModuleImpl service = getAppModule();
        idiomaViewImpl idioma =  service.getidiomaView1();
        Row idiRow = idioma.getCurrentRow();*/
        BindingContainer bindings = getBindings();
        OperationBinding operationBinding = 
            bindings.getOperationBinding("Commit");
        Object result = operationBinding.execute();
        if (!operationBinding.getErrors().isEmpty()) {
            return null;
        }
        return "crearNivel";
    }
    
    public AppModuleImpl getAppModule() {
        FacesContext ctx = FacesContext.getCurrentInstance();
        ValueBinding vb = ctx.getApplication().createValueBinding("#{data}");
        BindingContext bc = (BindingContext)vb.getValue(ctx);
        DCDataControl dc = bc.findDataControl("AppModuleDataControl");
        ApplicationModule am = (ApplicationModule)dc.getDataProvider();
        return (AppModuleImpl)am;
    }

    public void setPanelGroup2(CorePanelGroup panelGroup2) {
        this.panelGroup2 = panelGroup2;
    }

    public CorePanelGroup getPanelGroup2() {
        return panelGroup2;
    }

    public void setPanelGroup3(CorePanelGroup panelGroup3) {
        this.panelGroup3 = panelGroup3;
    }

    public CorePanelGroup getPanelGroup3() {
        return panelGroup3;
    }


    public void setTable1(CoreTable table1) {
        this.table1 = table1;
    }

    public CoreTable getTable1() {
        return table1;
    }

    public void setColumn1(CoreColumn column1) {
        this.column1 = column1;
    }

    public CoreColumn getColumn1() {
        return column1;
    }


    public void setColumn2(CoreColumn column2) {
        this.column2 = column2;
    }

    public CoreColumn getColumn2() {
        return column2;
    }


    public void setCommandLink1(CoreCommandLink commandLink1) {
        this.commandLink1 = commandLink1;
    }

    public CoreCommandLink getCommandLink1() {
        return commandLink1;
    }

    public void setCommandLink2(CoreCommandLink commandLink2) {
        this.commandLink2 = commandLink2;
    }

    public CoreCommandLink getCommandLink2() {
        return commandLink2;
    }

    public void setCommandButton3(CoreCommandButton commandButton3) {
        this.commandButton3 = commandButton3;
    }

    public CoreCommandButton getCommandButton3() {
        return commandButton3;
    }

    public void setCommandButton1(CoreCommandButton commandButton1) {
        this.commandButton1 = commandButton1;
    }

    public CoreCommandButton getCommandButton1() {
        return commandButton1;
    }

    public void setCommandButton2(CoreCommandButton commandButton2) {
        this.commandButton2 = commandButton2;
    }

    public CoreCommandButton getCommandButton2() {
        return commandButton2;
    }

    public void setPanelForm1(CorePanelForm panelForm1) {
        this.panelForm1 = panelForm1;
    }

    public CorePanelForm getPanelForm1() {
        return panelForm1;
    }

    public void setInputText1(CoreInputText inputText1) {
        this.inputText1 = inputText1;
    }

    public CoreInputText getInputText1() {
        return inputText1;
    }

    public String commandButton3_action() {
        BindingContainer bindings = getBindings();
        OperationBinding operationBinding = 
            bindings.getOperationBinding("Create");
        Object result = operationBinding.execute();
        if (!operationBinding.getErrors().isEmpty()) {
            return null;
        }
         JSFUtils.setExpressionValue("#{bindings.mostrar.inputValue}",true);        
        return null;
    }

    public void setCommandButton4(CoreCommandButton commandButton4) {
        this.commandButton4 = commandButton4;
    }

    public CoreCommandButton getCommandButton4() {
        return commandButton4;
    }

    public String commandButton4_action() {
        BindingContainer bindings = getBindings();
        OperationBinding operationBinding = 
            bindings.getOperationBinding("Rollback");
        Object result = operationBinding.execute();
        if (!operationBinding.getErrors().isEmpty()) {
            return null;
        }
        JSFUtils.setExpressionValue("#{bindings.mostrar.inputValue}",false);
        return null;
    }

    public String commandLink1_action() {
        BindingContainer bindings = getBindings();
        OperationBinding operationBinding = 
            bindings.getOperationBinding("setCurrentRowWithKey");
        Object result = operationBinding.execute();
        if (!operationBinding.getErrors().isEmpty()) {
            return null;
        }
        JSFUtils.setExpressionValue("#{bindings.mostrar.inputValue}",true);
        return null;
    }

    public void setCommandButton5(CoreCommandButton commandButton5) {
        this.commandButton5 = commandButton5;
    }

    public CoreCommandButton getCommandButton5() {
        return commandButton5;
    }

    public String commandButton5_action() {
        BindingContainer bindings = getBindings();
        OperationBinding operationBinding = 
            bindings.getOperationBinding("Commit");
        Object result = operationBinding.execute();
        if (!operationBinding.getErrors().isEmpty()) {
            return null;
        }
        JSFUtils.setExpressionValue("#{bindings.mostrar.inputValue}",false);
        return null;
    }

    public String commandLink2_action() {
        BindingContainer bindings = getBindings();
        OperationBinding operationBinding = 
            bindings.getOperationBinding("setCurrentRowWithKey");
        Object result = operationBinding.execute();
        if (!operationBinding.getErrors().isEmpty()) {
            return null;
        }
        AppModuleImpl service = getAppModule();                
        idiomaViewImpl  idioma = service.getidiomaView1();        
        try{
            idioma.removeCurrentRow();
            service.getDBTransaction().commit(); 
        }
        catch(Exception e){
        
        }
        
               
        
        return null;
        
    }
}
